package io.gitee.caoxiaoyu97.log.dynamic.level.logback;

import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.LoggerContext;
import io.gitee.caoxiaoyu97.log.dynamic.level.LogDynamicLevelEnhancer;
import org.slf4j.ILoggerFactory;
import org.slf4j.impl.StaticLoggerBinder;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/*********************************************************
 * 文件名称：BftsLevelMatchUtil.java
 * 系统名称：bfts
 * 模块名称：com.hundsun.tbsp.bfts.other.base.log.log4j
 * 功能说明：
 * 开发人员 @author：caoxy31978
 * 开发时间 @date：2025/9/23 14:01
 * 修改记录：程序版本  修改日期  修改人员  修改单号  修改说明
 *********************************************************/
public class LogBackLogDynamicLevelEnhancer extends LogDynamicLevelEnhancer {
    private static final Map<String, Level> levelMap = new ConcurrentHashMap<>();
    private static final LogbackLogDynamicLevelMatchFilter logbackLogDynamicLevelMatchFilter = new LogbackLogDynamicLevelMatchFilter();

    private LoggerContext getLoggerContext() {
        ILoggerFactory factory = StaticLoggerBinder.getSingleton().getLoggerFactory();
        return (LoggerContext)factory;
    }

    @Override
    protected void enhance() {
        getLoggerContext().getTurboFilterList().addIfAbsent(logbackLogDynamicLevelMatchFilter);
    }
}
